package com.kkkkkba.search.dataSource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kkkkkba.search.model.dto.code.CodeQueryRequest;
import com.kkkkkba.search.model.vo.CodeVO;
import com.kkkkkba.search.service.CodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 代码服务实现
 *
 */
@Service
@Slf4j
public class CodeDataSource implements DataSource<CodeVO> {

    @Resource
    private CodeService codeService;

    @Override
    public Page<CodeVO> doSearch(String searchText, long PageNum, long PageSize) {
        CodeQueryRequest codeQueryRequest = new CodeQueryRequest();
        codeQueryRequest.setSearchText(searchText);
        codeQueryRequest.setCurrent(PageNum);
        codeQueryRequest.setPageSize(PageSize);
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        Page<CodeVO> codeVOPage = codeService.listCodeVOByPage(codeQueryRequest, request);
        return codeVOPage;
    }
}




